﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartCity.BasicData.Api.Application.Command.Department;
using SmartCity.BasicData.Api.DTOs;
using SmartCity.BasicData.ErrorCoce;

namespace SmartCity.BasicData.Api.Controllers
{
    /// <summary>
    /// 部门控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 注入中介者组件
        /// </summary>
        /// <param name="mediator"></param>
        public DepartmentController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 使用递归查询部门树状数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<DepartmentDto>>> GetDepartmentTree([FromQuery] GetDepartmentCommand request)
        {

            return mediator.Send(request);
        }
    }
}